﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Mail;
using System.Text;
using System.Threading.Tasks;

namespace BucaUtils
{
    public static class EmailHelper
    {
        public static bool SendMail(string fromMail, string fromDisplay, string toMail, string cc, string bcc, string smtpServer, int port, string userNameMail, string passwordMail, string subject, string body, bool isEnableSsl, bool isBodyHtml=false)
        {
            bool flag;
            var client = new SmtpClient();
            var message = new MailMessage();
            try
            {
                var address = new MailAddress(fromMail, fromDisplay);
                client.Host = smtpServer;
                client.Port = port;
                message.From = address;
                var strArray = toMail.Split(new char[] { ';' });
                foreach (var str in strArray)
                {
                    message.To.Add(str);
                }
                message.Subject = subject;
                if (!string.IsNullOrEmpty(cc))
                {
                    var strCc = cc.Split(new char[] { ';' });
                    foreach (var str in strCc)
                    {
                        message.CC.Add(str);
                    }
                }
                if (!string.IsNullOrEmpty(bcc))
                {
                    var strBcc = bcc.Split(new char[] { ';' });
                    foreach (var str in strBcc)
                    {
                        message.Bcc.Add(new MailAddress(str));
                    }
                }
                message.IsBodyHtml = isBodyHtml;
                message.Body = body;
                client.EnableSsl = isEnableSsl;
                var credential = new NetworkCredential(userNameMail, passwordMail);
                client.Credentials = credential;
                client.Send(message);
                flag = true;
            }
            catch (Exception)
            {
                flag = false;
            }
            return flag;
        }
    }
    public static class EmailTemplateMaker
    {
        public static string RecoverPassword() { return "~/Content/EmailTemplate/RecoverPassword.html"; }
        public static string PasswordReseted() { return "~/Content/EmailTemplate/PasswordReseted.html"; }
        public static string Contact() { return "~/Content/EmailTemplate/Contact.html"; }
    }
}
